/**********************************************************************************************/
/* FBL_ArraySetIterator.cpp																	  */
/*                                                                       					  */
/* Copyright Paradigma, 1993-2006                                        					  */
/* All Rights Reserved.                                                 					  */
/**********************************************************************************************/

#include <VShared/FBL/publ/Headers/StdAfx.h>

#include <VShared/FBL/publ/Sets/FBL_ArraySetIterator.h>

#include <VShared/FBL/publ/Sets/FBL_ArraySet.h>


/**********************************************************************************************/
FBL_Begin_Namespace


/**********************************************************************************************/
ArraySetIterator::ArraySetIterator( void ) :
	mpSet( NULL )
{
	pCurrentItem = NULL;
	mColumnCount = 1;
}


/**********************************************************************************************/
ArraySetIterator::ArraySetIterator( const ArraySet& inSet ) :
	mpSet( &inSet )
{
	pCurrentItem = mpSet->pStart;
	mColumnCount = 1;
}


/**********************************************************************************************/
ArraySetIterator::~ArraySetIterator( void ) 	
{ 

}


#pragma mark -


/**********************************************************************************************/
void ArraySetIterator::ReadRow( ID_TYPE* outRow ) const
{
	memcpy(outRow, pCurrentItem, sizeof(*pCurrentItem) * mColumnCount);
}

 
/**********************************************************************************************/
bool ArraySetIterator::First( void ) 	
{ 
	if( mpSet->pStart == mpSet->pFinish )
		return false;
	else
	{ 
		pCurrentItem = mpSet->pStart; 
		return true;
	}
}

/**********************************************************************************************/
bool ArraySetIterator::Last( void ) 	
{ 
	if( mpSet->pStart == mpSet->pFinish )
	{
		return false;		
	}
	else
	{ 
		pCurrentItem = mpSet->pFinish - mColumnCount; 
		return true;
	}
}

/**********************************************************************************************/
bool ArraySetIterator::Next( void ) 	
{ 
	if( pCurrentItem + mColumnCount < mpSet->pFinish )
	{
		pCurrentItem += mColumnCount;
		return true;
	}
	else 
	{
		return false;	
	}
}

/**********************************************************************************************/
bool ArraySetIterator::Prev( void ) 	
{ 
	if( pCurrentItem - mColumnCount >= mpSet->pStart )
	{
		pCurrentItem -= mColumnCount;
		return true;
	}
	else 
	{
		return false;			
	}
}

/**********************************************************************************************/
bool ArraySetIterator::GoTo( ulong inIndex )
{
	FBL_CHECK( inIndex > 0 ); 	
	
	if( inIndex <= mpSet->get_Count() )
	{
		pCurrentItem = mpSet->pStart + (inIndex - 1) * mColumnCount;
		return true;
	}
	else
	{	
		pCurrentItem = NULL;
		return false;
	}
}


/**********************************************************************************************/
FBL_End_Namespace
